package util

import (
	"log/slog"
	"statsphere/pb"
	"statsphere/pkg/cache"
)

func PopPtIdList(batchId string, ptIds []string, errItems []*pb.ErrItem) (isEnd bool) {
	// 返回知否结束
	slog.Debug("反控响应", "batchId", batchId, "pt_ids", ptIds)
	//
	isEnd = false
	// ctrl:bid:116_1724221929007
	key := "ctrl:bid:" + batchId
	// 删除set集合里面的点位
	er3 := cache.Rdb0.SRem(ctx, key, ptIds).Err()
	if er3 != nil {
		slog.Error("redis_error", "error", er3.Error())
	}
	// SCard,set获取长度,长度是0,就删除
	remainingLen, er2 := cache.Rdb0.SCard(ctx, key).Result()
	if er2 != nil {
		slog.Error("redis_SCard_error" + key + er2.Error())
		return
	}
	// 剩余长度为空, 删除key
	if remainingLen == 0 {
		e2 := cache.Rdb0.Del(ctx, key).Err()
		if e2 != nil {
			slog.Error("Del_error" + key + e2.Error())
		}
		e2 = cache.Rdb0.HDel(ctx, "ctrl:batch_id:count", batchId).Err()
		if e2 != nil {
			slog.Error("Del_error" + key + e2.Error())
		}
		isEnd = true
		return
	}

	return
}
